﻿using System;
using System.Reflection;
using System.Runtime.Serialization;

namespace EconomicInformationServiceWcf.Helpers
{
    public class SoapHeaderHelper
    {
        internal static string GetNamespace(Type type)
        {
            string result = null;
            var daAttrib = GetAttribute<DataContractAttribute>(type);
            if (daAttrib != null)
                result = daAttrib.Namespace;

            return result ?? string.Empty;
        }

        private static T GetAttribute<T>(MemberInfo memberInfo) where T : class
        {
            object[] customAttributes = memberInfo.GetCustomAttributes(typeof(T), false);
            if (customAttributes.Length > 0)
                return (T)customAttributes[0];
            return null;
        }
    }
}